

/**
 * 取保留小数位，不足的补0
 */
pub fn round_num_str(num: f64, rnum: usize) -> String{
    let result = round_num(num, rnum);
    let mut result_str = result.to_string();
    let result_list:Vec<&str> = result_str.split(".").collect();
    let len = result_list[1].len();
    if len < rnum {
       for _ in 0..(rnum-len) {
        result_str.push_str("0")
       }     
    }
    return result_str;
}


/**
 * 取保留小数位
 */
pub fn round_num(num: f64, rnum: usize) -> f64 {
    if rnum > 0{
        let dj = get_dj(rnum);
        return (num * dj).round() / dj;
    }else{
        return num.round();
    }
}

/**
 * 获取进制数
 */
pub fn get_dj(round_num: usize) -> f64 {
    return match round_num {
        1 => 10.0,
        2 => 100.0,
        3 => 1000.0,
        4 => 10000.0,
        5 => 100000.0,
        6 => 1000000.0,
        7 => 10000000.0,
        8 => 100000000.0,
        9 => 1000000000.0,
        10 => 1000000000.0,
        _ => 100.0,
    };
}
